clear
set more off
set maxvar 32000
set matsize 11000
set emptycells drop
pwd

use pik pik_key_parent year parent_agi  parent_wage parent_have_1040 dob_month dob_day dob_year dob_year_mom dob_year_dad  birth_order parent_child_home parent_child_away parent_fil_stat parent_mafid pob_fips first_year_1040 male us_born parent_sched_se using ${raw_data}/irs1040_universe_parent.dta if year <= $max_parent_year & dob_year<=first_year_1040, clear //RENAME FILE NAME
destring pik, replace

sort pik year
xtset pik year

************************************************************
**************1) RD  SETUP (with Parent Data)***************
************************************************************
keep if dob_month==1 | dob_month==2 |dob_month==11 |dob_month==12
do ${main}/dos/tax/build/build_support/assign_var.do
keep if taxyr_cut>=1979


**************************************
******2) PREDICT Parent 1040 AGI (Prior to 1994) using previous observed 1040 (simple OLS). ******


**************************************
xtset pik year
do ${main}/dos/tax/build/build_support/predict_agi_setup.do
do ${main}/dos/tax/build/build_support/predict_agi.do
do ${main}/dos/tax/build/build_support/mstat.do

**************************************************************************
*3) Adjust birth_order variable using number of children reported
*************************************************************************
do ${main}/dos/tax/build/build_support/birth_order.do


**************************************************************************
*4) Construct ELIGIBLE EITC AMOUNT (w/ and w/o child born near cutoff)
**************************************************************************
set more off
***Use just tax year of birth
keep if taxyr_cut == year
merge m:1 taxyr_cut using ${supp_data}/eitc_params_yr, keep(match master) keepusing(eitc_in* eitc_out* eitc_max* ) gen(_m_eitc)
save ${clean_data}/taxyrcut_parents, replace

do ${main}/dos/tax/build/build_support/eitc_elig_slim.do

********TAXSIM Info (Change in Tax Burden due to extra dependent)**********
do ${main}/dos/tax/build/build_support/taxsim.do


*****CLEANUP*******
gen dob_dow = dow(dob)
sort year
order pik taxyr_cut year birth_order* *agiz_unadj parent_eitc_unadj parent_eitc_unadjnk i_*eitcany i_*noeitc*  i_*noeitc*
capture drop eitc_in* eitc_out* eitc_max*
save ${clean_data}/taxyrcut_parents_small, replace
